import { defineStore } from "pinia";
import { ref, computed } from "vue";

// 组合式 api
// 定义一个名为 login 的 store 并导出
export const useLoginStore = defineStore('login', () => {
    const LOGIN_REGISTER_TYPE = {
        LOGIN: 'login',
        REGISTER: 'register'
    };
    // 定义登录或者注册的状态
    const loginRegisterType = ref(LOGIN_REGISTER_TYPE.LOGIN);

    const toRegister = () => { loginRegisterType.value = LOGIN_REGISTER_TYPE.REGISTER; };
    const toLogin = () => { loginRegisterType.value = LOGIN_REGISTER_TYPE.LOGIN; };

    const isLogin = computed(() => loginRegisterType.value === LOGIN_REGISTER_TYPE.LOGIN);
    const isRegister = computed(() => loginRegisterType.value === LOGIN_REGISTER_TYPE.REGISTER);


    // 记录登录数据
    const loginData = ref({
        username: 'admin',
        password: 'admin'
    });
    // 记录注册数据
    const registerData = ref({
        username: '',
        password: '',
        confirmPassword: ''
    });



    return {
        loginRegisterType,
        toRegister,
        toLogin,
        isLogin,
        isRegister,
        loginData,
        registerData,
    }

});